; (function () {
  // 基于 supply.html 的移动端 rem 适配
  function setRem() {
    const base = 100 * (document.documentElement.clientWidth / 750);
    document.documentElement.style.fontSize = base + 'px';
  }
  setRem();
  window.addEventListener('resize', setRem);

  // 简版：不依赖 getEnterpriseInfo，直接从 cookie 读取企业编号
  const enterpriseIdFromCookie = (function(){
    try { return getCookie && getCookie('enterprise'); } catch(e) { return ''; }
  })();

  new Vue({
    el: '#app',
    data() {
      return {
        loading: false,
        tableData: [],
        enterpriseId: enterpriseIdFromCookie || '',
      }
    },
    mounted() {
      this.getList();
    },
    methods: {
      statusTagType(row) {
        const s = String(row.Row_Status || '');
        if (s === '2') return 'success'; // 接受/已确认
        if (s === '3') return 'danger'; // 拒绝/关闭
        if (s === '1') return 'warning'; // 审核中/待处理
        return 'info'; // 待确认/其他
      },
      formatStatus(row) {
        const s = String(row.Row_Status || '');
        if (s === '2') return '已确认';
        if (s === '3') return '已拒绝';
        if (s === '1') return '处理中';
        return '待确认';
      },
      async getList() {
        try {
          this.loading = true;
          if (!this.enterpriseId) {
            this.tableData = [];
            this.loading = false;
            return;
          }
          const Condition = `Enterprise_Info_SerialNumber='${this.enterpriseId}'`;
          const res = await httpRequest({
            url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
            type: 'POST',
            data: {
              Data: 'purchase_order',
              Condition,
            }
          });
          this.tableData = Array.isArray(res) ? res : (res?.data || []);
        } catch (e) {
          console.error(e);
          this.$message && this.$message.error('加载采购订单失败');
        } finally {
          this.loading = false;
        }
      },
      toDetail(row) {
        // 暂不跳详情，后续再接入最终页面
      }
    }
  });
})();